package com.fc.v2.controller.gen;

import com.fc.v2.common.base.BaseController;
import com.fc.v2.common.domain.AjaxResult;
import com.fc.v2.common.domain.ResultTable;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.model.auto.Carousel;
import com.fc.v2.service.CarouselService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 首页轮播图片表Controller
 * @ClassName: CarouselController
 * @author fuce
 * @date 2021-06-08 22:10:58
 */
@Api(value = "首页轮播图片表")
@Controller
@RequestMapping("/CarouselController")
public class CarouselController extends BaseController{
	
	private String prefix = "gen/carousel";
	
	@Autowired
	private CarouselService carouselService;
	
	
	/**
	 * 首页轮播图片表页面展示
	 * @param model
	 * @return String
	 * @author fuce
	 */
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/view")
	@RequiresPermissions("gen:carousel:view")
    public String view(ModelMap model)
    {
        return prefix + "/list";
    }
	
	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "首页轮播图片表", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/list")
	@RequiresPermissions("gen:carousel:list")
	@ResponseBody
	public ResultTable list(Tablepar tablepar,Carousel carousel){
		PageInfo<Carousel> page=carouselService.list(tablepar,carousel) ; 
		return pageTable(page.getList(),page.getTotal());
	}
	
	/**
     * 新增跳转
     */
	@ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }
	
    /**
     * 新增保存
     * @param 
     * @return
     */
	//@Log(title = "首页轮播图片表新增", action = "111")
	@ApiOperation(value = "新增", notes = "新增")
	@PostMapping("/add")
	@RequiresPermissions("gen:carousel:add")
	@ResponseBody
	public AjaxResult add(Carousel carousel){
		int b=carouselService.insertSelective(carousel);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 首页轮播图片表删除
	 * @param ids
	 * @return
	 */
	//@Log(title = "首页轮播图片表删除", action = "111")
	@ApiOperation(value = "删除", notes = "删除")
	@DeleteMapping("/remove")
	@RequiresPermissions("gen:carousel:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=carouselService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	
	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "修改跳转", notes = "修改跳转")
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map)
    {
        map.put("Carousel", carouselService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }
	
	/**
     * 修改保存
     */
    //@Log(title = "首页轮播图片表修改", action = "111")
	@ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:carousel:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Carousel carousel)
    {
        return toAjax(carouselService.updateByPrimaryKeySelective(carousel));
    }

	@ApiOperation(value = "所有轮播图片", notes = "所有轮播图片")
	@GetMapping("/getAllCarousel")
	@ResponseBody
	public ResultTable getAllImages(Tablepar tablepar) {
		PageInfo<Carousel> page = carouselService.getAllCarousel(tablepar);
		return pageTable(page.getList(), page.getTotal());
	}

	@ApiOperation(value = "更改轮播图片状态", notes = "更改轮播图片状态")
	@PutMapping("/updateStatus")
	@ResponseBody
	public AjaxResult updateStatus(@RequestBody Carousel carousel) {
		int b = carouselService.updateStatus(carousel);
		return b > 0 ? success() : error();
	}
}
